<template>
  <div id="activeTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item prop="checkStatu">
          <el-select v-model="formInline.collegeId" placeholder="">
            <el-option
              v-for="item in collegeData"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="activityId">
          <el-input
            v-model="formInline.title"
            placeholder="章节名称"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch()">
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  msg: '活动分析-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          collegeId: '',
          title: '',
          createTime: [],
          startDate: '',
          endDate: '',
          collegeList: []
        }
      }
    }
  },
  data() {
    return {
      /** 反馈类型 */
      feedbackType: [],
      rules: {
        activityId: {},
        type: {},
        createTime: { type: 'array' }
      }
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startDate = newVal[0]
          this.formInline.endDate = newVal[1]
        } else {
          this.formInline.startDate = ''
          this.formInline.endDate = ''
        }
      },
      deep: true
    }
  },
  computed: {
    collegeData: function() {
      const defaultArr = [
        {
          id: '',
          name: '选择学院'
        }
      ]
      return defaultArr.concat(this.formInline.collegeList)
    }
  },
  mounted() {},
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$emit('toSearch')
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      this.setDefaultValue()
    },
    setDefaultValue() {
      this.formInline.collegeId = ''
      this.formInline.title = ''
      this.formInline.createTime = []
      this.formInline.startDate = ''
      this.formInline.endDate = ''
    }
  }
}
</script>

<style lang="less"></style>
